package gitdemo1.git3.tree;

public class BiTree {
    int val;
    BiTree left;
    BiTree right;

    BiTree() {}
    BiTree(int val) { this.val = val; }
    BiTree(int val, BiTree left, BiTree right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }

    public static void main(String[] args) {

        BiTree node5 = new BiTree(5, null, null);
        BiTree node4 = new BiTree(4, null, null);
        BiTree node3 = new BiTree(3, null, null);
        BiTree node2 = new BiTree(2, node4, node5);
        BiTree node1 = new BiTree(1, node2, node3);

//        swap(node1);
//        pre(node1);
     //   findx(node1, 2,0);
        int a[]=new int[]{21,30,52,35,69,70,90,61,78,99};
        int b=9;
        int c=4;
        change2(b,c);
        System.out.println(b+" "+c);
//        change1(a, 0, 9);
//        for (int k = 0; k < a.length; k++) {
//            System.out.println(a[k]);
//
//        }
    }

    private static void change2(int b, int c) {
        int a=b;
        b=c;
        c=a;
    }


    public static void swap(BiTree node){
        if (node != null) {

            BiTree temp=node.left;
            node.left=node.right;
            node.right=temp;

            swap(node.left);
            swap(node.right);
        }

    }




    //public static int i=0;
    //先序遍历
    public static void pre(BiTree node){
        if(node!=null){
            System.out.println(node.val);
//            System.out.println(i++);
            pre(node.left);
            pre(node.right);
        }
    }

    public static void findx(BiTree node,int k,int i){
        if(node!=null){

            if(k==i) {
                System.out.println(node.val );
            }
//            System.out.println(i++);
            findx(node.left,k,i+1);
            findx(node.right,k,i+2);
        }

    }

    public static void change1(int a[],int low,int high)
    {
        int i,j,t;
        i=low;j=high;
        if (i<j)
        {  while (i<j && a[i]%2!=0)   i++;
            while (i<j && a[j]%2==0)  j--;
            if (i!=j)
            {t=a[i];
                a[i]=a[j];
                a[j]=t;
            }
            change1(a,i+1,j-1);
        }

    }



}
